<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>删除信息</title>
<style type="text/css">
body {
	font-family: sans-serif;
	background-color: #4F4F4F;	
	color: #FFF3EE;
}
#left{
	float: left;
	position: absolute;
	top: 100px;
	left: 2.5%;
	right: auto;
	bottom: auto;
	width: 10%;
}

#right{
	float: left;
	position: absolute;
	top: 100px;
	left: auto;
	right: 2.5%;
	bottom: auto;
	width: 80%;
}

#tab{
	border-left: solid;
	border-bottom: solid;
	width: 80%;
	text-align:center;
}

td{
	border-right: solid;
	border-top: solid;
}

.button {
    border: none;
    background-color: #4F4F4F;	
	color: #FFF3EE;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    -webkit-transition-duration: 0.4s; /* Safari */
    transition-duration: 0.4s;
    cursor: pointer;
    width: 150px;
    height: 40px;
}

.button1 {
    background-color: white; 
    color: black; 
    border: 1px solid #2894FF;
    border-radius: 2px;
}

.button1:hover {
    background-color: #4F4F4F;	
	color: #FFF3EE;
    box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
}
</style>
</head>
<body>
<div id="left">
		<form action="deleteServlet" method="post">
			输入要删除的学号:<br><br> <input type="text" name="id"><br><br>
			<input type="submit" value="确认删除" class="button button1"><br>
		</form>
	</div>
	<div id="right">
		<table id="tab">
			<tr>
				<td>学号</td>
				<td>姓名</td>
				<td>成绩</td>
			</tr>
			<%
			try {
				Class.forName("com.mysql.jdbc.Driver");
				String url = "jdbc:mysql://localhost:3306/mydatabase";
				String username = "root";
				String password = null;
				Connection conn = DriverManager.getConnection(url, username, password);

				if (conn != null) {
					Statement stmt = null;
					ResultSet rs = null;
					String sql = "select * from studentinfo;";
					stmt = conn.createStatement();
					rs = stmt.executeQuery(sql);
					
					boolean flag = false;
					
					while (rs.next()) {
						if (!((String)session.getAttribute("user")).equals(rs.getString("userName"))) {
							continue;
						}
						
						out.print("<tr>");
						out.print("<td>"+rs.getString("id")+"</td><td>"+rs.getString("name")+"</td><td>"+rs.getInt("grade")+"</td>");
						out.print("</tr>");
						flag = true;
					}
					conn.close();
					
					if (!flag) {
						out.print("<tr><td colspan='3'>未查询到信息</td></tr>");
					}
				}
			} catch (Exception e) {
				out.print("<tr><td colspan='3'>未查询到信息</td></tr>");
			}
			%>
		</table>
	</div>
</body>
</html>